/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.planning.tactical.wizard.common;

import nl.cloudfarming.client.db.test.BaseContextTest;
import nl.cloudfarming.client.db.test.BaseContextTest.MockContextGlobalProvider;
import org.junit.Test;
import java.awt.event.ActionEvent;
import static junit.framework.Assert.*;
import java.awt.Component;
import javax.swing.JComboBox;
import nl.cloudfarming.client.model.ProductionUnit;
import nl.cloudfarming.client.planning.tactical.TacticalPlanningModule;
import org.openide.util.NbBundle;
import org.uispec4j.Panel;
import org.uispec4j.UISpec4J;
import org.uispec4j.finder.ComponentMatcher;
import static org.mockito.Mockito.*;

/**
 *
 * @author Merijn Zengers
 */

public class ActionTypeActionIT extends BaseContextTest{

    static {
        UISpec4J.init();
    }
    
    private final ComboBoxComponentMatcher comboBoxMatcher = new ComboBoxComponentMatcher();

    @Test
    public void testPanel() {
        ProductionUnit productionUnit = mock(ProductionUnit.class);
        
        MockContextGlobalProvider.add(productionUnit);
        
        ActionTypeAction action = new ActionTypeAction();
        ActionEvent event = mock(ActionEvent.class);
        
        action.actionPerformed(event);
        
        Panel panel = new Panel(action.getPanel());
        
        assertTrue(panel.containsComponent(comboBoxMatcher).isTrue());
        String option = NbBundle.getMessage(TacticalPlanningModule.class, "action.wizard.choose.actiontype.combobox.option1");
        assertTrue(panel.getComboBox().contains(option).isTrue());
        
        //Can't be executed due to the fact that the wizard panels are initialized and some hava validation which only runs in event thread
//        assertNotNull(MockDialogDisplayer.options);
//        assertTrue(MockDialogDisplayer.options[0] instanceof JButton);
//        
//        JButton okButton = (JButton) MockDialogDisplayer.options[0];
//        
//        for (ActionListener al : okButton.getActionListeners()) {
//            al.actionPerformed(event);
//        }
//        
//        Utilities.actionsGlobalContext().lookup(PlanningWizardAction.class);
    }

    class ComboBoxComponentMatcher implements ComponentMatcher {

        @Override
        public boolean matches(Component component) {
            return (component instanceof JComboBox);
        }
    }
    
}
